// https://leetcode.cn/problems/contains-duplicate-ii/description/


func containsNearbyDuplicate(nums []int, k int) bool {
	rec := make(map[int]int)
	for i := 0; i < len(nums); i++ {
		if _, e := rec[nums[i]]; e {
			if i - rec[nums[i]] >= -k && i - rec[nums[i]] <=k {
				return true
			}
		}
		rec[nums[i]] = i
	}
    return false
}